//
//  YCService.swift
//  YCNetworking
//
//  Created by YC on 2017/3/7.
//  Copyright © 2017年 YC. All rights reserved. mail:yangchong364@qq.com
//

import UIKit

public enum YCApiType: Int {
    case online
    case external
    case beta
};

public protocol YCServiceProtocol: class {
    var apiType: YCApiType { get }
    var onlineApiBaseUrl: String { get }
    var externalApiBaseUrl: String { get }
    var betaApiBaseUrl: String { get }
    var apiControllerName: String { get }
}


public class YCService {
    
    weak var child: YCServiceProtocol!
    
    public init () {
        if self is YCServiceProtocol {
            self.child = self as! YCServiceProtocol
        }else {
            NSException(name: NSExceptionName(rawValue: "Service初始化错误!"), reason: "子类没有实现YCServiceProtocol协议", userInfo: nil).raise()
        }
    }
    
    public var apiBaseUrl: String {
        get {
            switch self.child.apiType {
            case .online:
                return self.child.onlineApiBaseUrl
            case .external:
                return self.child.externalApiBaseUrl
            case .beta:
                return self.child.betaApiBaseUrl
            }
        }
    }
    var apiController: String {
        get {
            return self.child.apiControllerName
        }
    }
    
}
